package Exercise;

import java.util.Scanner;

/**
 * Description：
 * Author: zhangc
 * Date：2017/8/8 20:46
 */
public class LatestFibonacci {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        if (num < 0)
            System.out.println(-1);
        int pre = 0, next = 1;
        int temp;
        while (next < num) {
            temp = next;
            next = next + pre;
            pre = temp;
        }
        temp = next - num < num - pre ? next - num : num - pre;
        System.out.println(temp);
    }

}
